package priv.pfz.basedao.info;

import com.google.common.collect.Lists;
import lombok.Data;
import priv.pfz.basedao.sharding.ShardingMode;

import java.lang.reflect.Method;
import java.util.List;
import java.util.Map;

/**
 * 运行时解析得到的Dao信息
 * @author yyjxp
 * 2024/1/28 19:06
 */
@Data
public class DaoInfo {
    /**
     * 数据库名称
     */
    private String dbName;

    /**
     * 表名
     */
    private String tableName;

    /**
     * 是否开启逻辑删除功能
     */
    private boolean enableLogicDelete;

    /**
     * 逻辑删除列名
     */
    private String logicDeleteColumnName;
    private String logicDeleteColumnSql;

    /**
     * Entity类
     */
    private Class<?> entityClass;

    /**
     * Entity字段信息map
     */
    private Map<String, FieldInfo> fieldInfoMap;

    /**
     * Entity字段信息list
     */
    private List<FieldInfo> fieldInfos;

    /**
     * 获取entity非空字段值的字节码方法
     */
    private Method entityValueMapGetter;

    /**
     * select字段
     */
    private String[] selectColumns;

    /**
     * uniqueKey字段
     */
    private List<FieldInfo> uniqueKeyFieldInfos = Lists.newArrayList();

    /**
     * 切分键字段信息
     */
    private FieldInfo shardingKeyFieldInfo;

    /**
     * 分库分表模式
     */
    private ShardingMode shardingMode = ShardingMode.NO_SHARDING;

    public void setLogicDeleteColumnName(String logicDeleteColumnName) {
        this.logicDeleteColumnName = logicDeleteColumnName;
        this.logicDeleteColumnSql = "`" + logicDeleteColumnName + "`";
    }
}
